package com.tengju.bff.interfaces.shared.render;

import com.tengju.bff.interfaces.shared.ColumnVO;
import com.tengju.bff.interfaces.shared.Formatter;
import com.tengju.bff.interfaces.shared.KVVO;
import com.tengju.bff.interfaces.shared.TableVO;
import com.tengju.data.domain.model.analysis.Meta;
import com.tengju.data.domain.model.analysis.MetaType;
import com.tengju.data.domain.model.analysis.Row;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author chenhang
 * @Date 2021/7/12
 */
public class MockUtil {

    public static List<Row> mockData(Collection<Meta> metas,Integer num) {
        if (CollectionUtils.isEmpty(metas)) {
            return Collections.emptyList();
        }
        List<Row> rows = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            Row row = new Row();
            for (Meta meta : metas) {
                if (meta.getMetaType().equals(MetaType.Name) ||
                        meta.getMetaType().equals(MetaType.None) ||
                        meta.getMetaType().equals(MetaType.String)) {
                    row.put(meta.getSqlColName(),"mock" + randomInt());
                } else {
                    row.put(meta.getSqlColName(),randomDouble());
                }
            }
            rows.add(row);
        }
        return rows;
    }

    private static int randomInt() {
        return ThreadLocalRandom.current().nextInt(1000);
    }

    private static double randomDouble() {
        return ThreadLocalRandom.current().nextDouble();
    }


}
